package org.mybatis.generator.api.plus;

import static org.mybatis.generator.internal.util.JavaBeansUtil.getGetterMethodName;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.java.Parameter;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author wangfupeng
 */
public class MybatisUtilCommon {

    public static Integer COLUMN_FIELD_LENGTH = 2000;

    public static String newImageSrc = "";

    public static String configImageSrc = "";

    public static String searchImageSrc = "";

    public static String deleteImageSrc = "";

    public static String noImageSrc = "";

    public static String yesImageSrc = "";

    public static String editImageSrc = "";

    public static String loadingImageSrc = "";

    public static String plusImageSrc = "";

    public static String minusImageSrc = "";

    private static FullyQualifiedJavaType stringType;
    private static FullyQualifiedJavaType integerType;
    private static FullyQualifiedJavaType booleanType;
    private static FullyQualifiedJavaType byteType;
    private static FullyQualifiedJavaType doubleType;
    private static FullyQualifiedJavaType floatType;
    private static FullyQualifiedJavaType longType;
    private static FullyQualifiedJavaType shortType;
    private static FullyQualifiedJavaType bigDecimalType;
    private static FullyQualifiedJavaType dateType;
    private static FullyQualifiedJavaType characterType;

    static {
        stringType = new FullyQualifiedJavaType("java.lang.String");
        integerType = new FullyQualifiedJavaType("java.lang.Integer");
        booleanType = new FullyQualifiedJavaType("java.lang.Boolean");
        byteType = new FullyQualifiedJavaType("java.lang.Byte");
        doubleType = new FullyQualifiedJavaType("java.lang.Double");
        floatType = new FullyQualifiedJavaType("java.lang.Float");
        longType = new FullyQualifiedJavaType("java.lang.Long");
        shortType = new FullyQualifiedJavaType("java.lang.Short");
        bigDecimalType = new FullyQualifiedJavaType("java.lang.BigDecimal");
        dateType = new FullyQualifiedJavaType("java.util.Date");
        characterType = new FullyQualifiedJavaType("java.lang.Character");
    }

    public static String toLowerCaseAtFirstCharacter(String tableName) {
        StringBuilder sb = new StringBuilder(tableName);
        sb.setCharAt(0, Character.toLowerCase(sb.charAt(0)));
        return sb.toString();
    }

    public static String toUpperCaseAtFirstCharacter(String tableName) {
        StringBuilder sb = new StringBuilder(tableName);
        sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
        return sb.toString();
    }

    public static void addParameterForPrimaryKeyColumnsInMethodSelectByPrimaryKey(Method method, IntrospectedTable introspectedTable) {
        List<IntrospectedColumn> introspectedColumns = introspectedTable.getPrimaryKeyColumns();
        Iterator<IntrospectedColumn> iterator = introspectedColumns.iterator();
        while (iterator.hasNext()) {
            IntrospectedColumn introspectedColumn = iterator.next();
            FullyQualifiedJavaType fullyQualifiedJavaType = introspectedColumn
                    .getFullyQualifiedJavaType();
            String columnName = introspectedColumn.getJavaProperty();
            if (introspectedColumn.isBLOBColumn()) {
            } else {
                if (fullyQualifiedJavaType.isPrimitive()) {
                    if ("boolean".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        method.addParameter(new Parameter(booleanType, columnName));
                    } else if ("byte".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        method.addParameter(new Parameter(byteType, columnName));
                    } else if ("double".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        method.addParameter(new Parameter(doubleType, columnName));
                    } else if ("float".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        method.addParameter(new Parameter(floatType, columnName));
                    } else if ("int".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        method.addParameter(new Parameter(integerType, columnName));
                    } else if ("long".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        method.addParameter(new Parameter(longType, columnName));
                    } else if ("short".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        method.addParameter(new Parameter(shortType, columnName));
                    } else if ("char".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        method.addParameter(new Parameter(characterType, columnName));
                    }
                } else if ("java.lang.Boolean".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    method.addParameter(new Parameter(booleanType, columnName));
                } else if ("java.lang.Byte".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    method.addParameter(new Parameter(byteType, columnName));
                } else if ("java.lang.Double".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    method.addParameter(new Parameter(doubleType, columnName));
                } else if ("java.lang.Integer".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    method.addParameter(new Parameter(integerType, columnName));
                } else if ("java.lang.Long".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    method.addParameter(new Parameter(longType, columnName));
                } else if ("java.lang.Short".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    method.addParameter(new Parameter(shortType, columnName));
                } else if ("java.lang.BigDecimal".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    method.addParameter(new Parameter(bigDecimalType, columnName));
                } else if ("java.util.Date".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    method.addParameter(new Parameter(dateType, columnName));
                } else if ("java.lang.String".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    method.addParameter(new Parameter(stringType, columnName));
                }
            }
        }
    }

    public static String getParameterWithAnnotationForPrimaryKeyColumns(IntrospectedTable introspectedTable) {
        List<IntrospectedColumn> introspectedColumns = introspectedTable.getPrimaryKeyColumns();
        Iterator<IntrospectedColumn> iterator = introspectedColumns.iterator();
        String parameter = "";
        while (iterator.hasNext()) {
            IntrospectedColumn introspectedColumn = iterator.next();
            FullyQualifiedJavaType fullyQualifiedJavaType = introspectedColumn
                    .getFullyQualifiedJavaType();
            String columnName = introspectedColumn.getJavaProperty();
            if (introspectedColumn.isBLOBColumn()) {
            } else {
                if (fullyQualifiedJavaType.isPrimitive()) {
                    if ("boolean".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        parameter = parameter + " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\") Boolean " + columnName + ",";
                    } else if ("byte".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        parameter = parameter + " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\")  Byte " + columnName + ",";
                    } else if ("double".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        parameter = parameter + " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\") Double " + columnName + ",";
                    } else if ("float".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        parameter = parameter + " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\") Float " + columnName + ",";
                    } else if ("int".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        parameter = parameter + " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\") Integer " + columnName + ",";
                    } else if ("long".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        parameter = parameter + " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\") Long " + columnName + ",";
                    } else if ("short".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        parameter = parameter + " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\") Short " + columnName + ",";
                    } else if ("char".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        parameter = parameter + " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\") Character " + columnName + ",";
                    }
                } else if ("java.lang.Boolean".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    parameter = parameter + " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\") Boolean " + columnName + ",";
                } else if ("java.lang.Byte".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    parameter = parameter + " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\") Byte " + columnName + ",";
                } else if ("java.lang.Double".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    parameter = parameter + " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\") Double " + columnName + ",";
                } else if ("java.lang.Integer".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    parameter = parameter + " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\") Integer " + columnName + ",";
                } else if ("java.lang.Long".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    parameter = parameter + " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\") Long " + columnName + ",";
                } else if ("java.lang.Short".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    parameter = parameter + " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\") Short " + columnName + ",";
                } else if ("java.lang.BigDecimal".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    parameter = parameter + " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\") BigDecimal " + columnName + ",";
                } else if ("java.util.Date".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    parameter = parameter + " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\") Date " + columnName + ",";
                } else if ("java.lang.String".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    parameter = parameter + " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\") String " + columnName + ",";
                }
            }
        }
        return parameter.substring(0,parameter.length()-1);
    }


    public static String getParameterWithoutAnnotationForPrimaryKeyColumns(IntrospectedTable introspectedTable) {
        List<IntrospectedColumn> introspectedColumns = introspectedTable.getPrimaryKeyColumns();
        Iterator<IntrospectedColumn> iterator = introspectedColumns.iterator();
        String parameter = "";
        while (iterator.hasNext()) {
            IntrospectedColumn introspectedColumn = iterator.next();
            FullyQualifiedJavaType fullyQualifiedJavaType = introspectedColumn
                    .getFullyQualifiedJavaType();
            String columnName = introspectedColumn.getJavaProperty();
            if (introspectedColumn.isBLOBColumn()) {
            } else {
                if (fullyQualifiedJavaType.isPrimitive()) {
                    if ("boolean".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        parameter = parameter + " Boolean " + columnName + ",";
                    } else if ("byte".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        parameter = parameter + " Byte " + columnName + ",";
                    } else if ("double".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        parameter = parameter + " Double " + columnName + ",";
                    } else if ("float".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        parameter = parameter + " Float " + columnName + ",";
                    } else if ("int".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        parameter = parameter + " Integer " + columnName + ",";
                    } else if ("long".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        parameter = parameter + " Long " + columnName + ",";
                    } else if ("short".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        parameter = parameter + " Short " + columnName + ",";
                    } else if ("char".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        parameter = parameter + " Character " + columnName + ",";
                    }
                } else if ("java.lang.Boolean".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    parameter = parameter + " Boolean " + columnName + ",";
                } else if ("java.lang.Byte".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    parameter = parameter + " Byte " + columnName + ",";
                } else if ("java.lang.Double".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    parameter = parameter + " Double " + columnName + ",";
                } else if ("java.lang.Integer".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    parameter = parameter + " Integer " + columnName + ",";
                } else if ("java.lang.Long".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    parameter = parameter + " Long " + columnName + ",";
                } else if ("java.lang.Short".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    parameter = parameter + " Short " + columnName + ",";
                } else if ("java.lang.BigDecimal".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    parameter = parameter + " BigDecimal " + columnName + ",";
                } else if ("java.util.Date".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    parameter = parameter + " Date " + columnName + ",";
                } else if ("java.lang.String".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    parameter = parameter + " String " + columnName + ",";
                }
            }
        }
        return parameter.substring(0,parameter.length()-1);
    }


    public static String getParameterWithoutAnnotationWithoutTypeForPrimaryKeyColumns(IntrospectedTable introspectedTable) {
        List<IntrospectedColumn> introspectedColumns = introspectedTable.getPrimaryKeyColumns();
        Iterator<IntrospectedColumn> iterator = introspectedColumns.iterator();
        String parameter = "";
        while (iterator.hasNext()) {
            IntrospectedColumn introspectedColumn = iterator.next();
            FullyQualifiedJavaType fullyQualifiedJavaType = introspectedColumn
                    .getFullyQualifiedJavaType();
            String columnName = introspectedColumn.getJavaProperty();
            if (introspectedColumn.isBLOBColumn()) {
            } else {
                parameter = parameter + " " + columnName + ",";
            }
        }
        return parameter.substring(0,parameter.length()-1);
    }


    public static void addParameterWithAnnotationForPrimaryKeyColumnsInMethodSelectByPrimaryKey(Method method, IntrospectedTable introspectedTable) {
        List<IntrospectedColumn> introspectedColumns = introspectedTable.getPrimaryKeyColumns();
        Iterator<IntrospectedColumn> iterator = introspectedColumns.iterator();
        while (iterator.hasNext()) {
            IntrospectedColumn introspectedColumn = iterator.next();
            FullyQualifiedJavaType fullyQualifiedJavaType = introspectedColumn
                    .getFullyQualifiedJavaType();
            String columnName = introspectedColumn.getJavaProperty();
            if (introspectedColumn.isBLOBColumn()) {
            } else {
                if (fullyQualifiedJavaType.isPrimitive()) {
                    if ("boolean".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        method.addParameter(new Parameter(booleanType, columnName, " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\")"));
                    } else if ("byte".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        method.addParameter(new Parameter(byteType, columnName, " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\")"));
                    } else if ("double".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        method.addParameter(new Parameter(doubleType, columnName, " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\")"));
                    } else if ("float".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        method.addParameter(new Parameter(floatType, columnName, " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\")"));
                    } else if ("int".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        method.addParameter(new Parameter(integerType, columnName, " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\")"));
                    } else if ("long".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        method.addParameter(new Parameter(longType, columnName, " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\")"));
                    } else if ("short".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        method.addParameter(new Parameter(shortType, columnName, " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\")"));
                    } else if ("char".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        method.addParameter(new Parameter(characterType, columnName, " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\")"));
                    }
                } else if ("java.lang.Boolean".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    method.addParameter(new Parameter(booleanType, columnName, " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\")"));
                } else if ("java.lang.Byte".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    method.addParameter(new Parameter(byteType, columnName, " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\")"));
                } else if ("java.lang.Double".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    method.addParameter(new Parameter(doubleType, columnName, " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\")"));
                } else if ("java.lang.Integer".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    method.addParameter(new Parameter(integerType, columnName, " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\")"));
                } else if ("java.lang.Long".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    method.addParameter(new Parameter(longType, columnName, " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\")"));
                } else if ("java.lang.Short".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    method.addParameter(new Parameter(shortType, columnName, " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\")"));
                } else if ("java.lang.BigDecimal".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    method.addParameter(new Parameter(bigDecimalType, columnName, " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\")"));
                } else if ("java.util.Date".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    method.addParameter(new Parameter(dateType, columnName, " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\")"));
                } else if ("java.lang.String".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    method.addParameter(new Parameter(stringType, columnName, " @ApiParam(value = \"" + columnName + "\") @PathVariable(value=\""+columnName+"\")"));
                }
            }
        }
    }

    public static boolean getExistNonePrimaryKeyColumns(IntrospectedTable introspectedTable) {
        List<IntrospectedColumn> introspectedColumns = introspectedTable.getPrimaryKeyColumns();
        List<IntrospectedColumn> introspectedColumnsAll = introspectedTable.getAllColumns();
        if (introspectedColumns.size() == introspectedColumnsAll.size()) {
            return false;
        }
        return true;
    }

    public static String getPathForPrimaryKeyColumns(IntrospectedTable introspectedTable) {
        List<IntrospectedColumn> introspectedColumns = introspectedTable.getPrimaryKeyColumns();
        Iterator<IntrospectedColumn> iterator = introspectedColumns.iterator();
        String pathString = "";
        while (iterator.hasNext()) {
            IntrospectedColumn introspectedColumn = iterator.next();
            String columnName = introspectedColumn.getJavaProperty();
            if (introspectedColumn.isBLOBColumn()) {
            } else {
                pathString += "/{" + columnName + "}";
            }
        }
        return pathString;
    }

    public static String getParameterValueForPrimaryKeyColumns(IntrospectedTable introspectedTable) {
        List<IntrospectedColumn> introspectedColumns = introspectedTable.getPrimaryKeyColumns();
        Iterator<IntrospectedColumn> iterator = introspectedColumns.iterator();
        String pathString = "";
        boolean isFirstParameter = true;
        while (iterator.hasNext()) {
            IntrospectedColumn introspectedColumn = iterator.next();
            String columnName = introspectedColumn.getJavaProperty();
            if (introspectedColumn.isBLOBColumn()) {
            } else {
                if (isFirstParameter) {
                    pathString += columnName;
                    isFirstParameter = false;
                } else {
                    pathString += ", " + columnName;
                }
            }
        }
        return pathString;
    }

    public static String getAnnotationForUpdateForPrimaryKeyColumns(IntrospectedTable introspectedTable, String model) {
        List<IntrospectedColumn> introspectedColumns = introspectedTable.getPrimaryKeyColumns();
        Iterator<IntrospectedColumn> iterator = introspectedColumns.iterator();
        String pathString = "";
        while (iterator.hasNext()) {
            IntrospectedColumn introspectedColumn = iterator.next();
            String columnName = introspectedColumn.getJavaProperty();

            FullyQualifiedJavaType fullyQualifiedJavaType = introspectedColumn
                    .getFullyQualifiedJavaType();

            String getterMethod = getGetterMethodName(
                    introspectedColumn.getJavaProperty(), fullyQualifiedJavaType);

            if (introspectedColumn.isBLOBColumn()) {
            } else {
                pathString += "+':" + columnName + ":'+#" + model + "." + getterMethod + "()";
            }
        }
        return pathString;
    }

    public static String getAnnotationForDeleteAndSelectForPrimaryKeyColumns(IntrospectedTable introspectedTable) {
        List<IntrospectedColumn> introspectedColumns = introspectedTable.getPrimaryKeyColumns();
        Iterator<IntrospectedColumn> iterator = introspectedColumns.iterator();
        String pathString = "";
        while (iterator.hasNext()) {
            IntrospectedColumn introspectedColumn = iterator.next();
            String columnName = introspectedColumn.getJavaProperty();
            if (introspectedColumn.isBLOBColumn()) {
            } else {
                pathString += "+':" + columnName + ":'+#" + columnName;
            }
        }
        return pathString;
    }

    public static void addParameterForColumnsWithMaxMinPrefixSuffixLike(Method method, IntrospectedTable introspectedTable) {
        List<IntrospectedColumn> introspectedColumns;
        if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
            introspectedColumns = introspectedTable.getNonBLOBColumns();
        } else {
            introspectedColumns = introspectedTable.getAllColumns();
        }
        Iterator<IntrospectedColumn> iterator = introspectedColumns.iterator();
        List<String> columnNames = new ArrayList<>();
        while (iterator.hasNext()) {
            IntrospectedColumn introspectedColumn = iterator.next();
            if (introspectedColumn.isBLOBColumn()) {
            } else {
                FullyQualifiedJavaType fullyQualifiedJavaType = introspectedColumn
                        .getFullyQualifiedJavaType();
                String columnName = introspectedColumn.getJavaProperty();
                if (columnNames.contains(columnName)) {
                } else {
                    columnNames.add(columnName);
                    if (fullyQualifiedJavaType.isPrimitive()) {
                        if ("boolean".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            method.addParameter(new Parameter(booleanType, columnName, " @ApiParam(value = \"" + columnName
                                    + "=true/false\") @RequestParam(value = \"" + columnName + "\", required = false)"));
                        } else if ("char".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            method.addParameter(new Parameter(characterType, columnName, " @ApiParam(value = \"" + columnName
                                    + "=此值\") @RequestParam(value = \"" + columnName + "\", required = false)"));
                        } else if ("byte".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            method.addParameter(new Parameter(byteType, columnName + "_max", " @ApiParam(value = \"" + columnName
                                    + "<=此值 \") @RequestParam(value = \"" + columnName + "_max\", required = false)"));
                            method.addParameter(new Parameter(byteType, columnName + "_min", " @ApiParam(value = \"" + columnName
                                    + ">=此值 \") @RequestParam(value = \"" + columnName + "_min\", required = false)"));
                            method.addParameter(new Parameter(byteType, columnName + "", " @ApiParam(value = \"" + columnName
                                    + "=此值 \") @RequestParam(value = \"" + columnName + "\", required = false)"));
                        } else if ("double".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            method.addParameter(new Parameter(doubleType, columnName + "_max", " @ApiParam(value = \"" + columnName
                                    + "<=此值 \") @RequestParam(value = \"" + columnName + "_max\", required = false)"));
                            method.addParameter(new Parameter(doubleType, columnName + "_min", " @ApiParam(value = \"" + columnName
                                    + ">=此值 \") @RequestParam(value = \"" + columnName + "_min\", required = false)"));
                            method.addParameter(new Parameter(doubleType, columnName + "", " @ApiParam(value = \"" + columnName
                                    + "=此值 \") @RequestParam(value = \"" + columnName + "\", required = false)"));
                        } else if ("float".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            method.addParameter(new Parameter(floatType, columnName + "_max", " @ApiParam(value = \"" + columnName
                                    + "<=此值 \") @RequestParam(value = \"" + columnName + "_max\", required = false)"));
                            method.addParameter(new Parameter(floatType, columnName + "_min", " @ApiParam(value = \"" + columnName
                                    + ">=此值 \") @RequestParam(value = \"" + columnName + "_min\", required = false)"));
                            method.addParameter(new Parameter(floatType, columnName + "", " @ApiParam(value = \"" + columnName
                                    + "=此值 \") @RequestParam(value = \"" + columnName + "\", required = false)"));
                        } else if ("int".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            method.addParameter(new Parameter(integerType, columnName + "_max", " @ApiParam(value = \"" + columnName
                                    + "<=此值 \") @RequestParam(value = \"" + columnName + "_max\", required = false)"));
                            method.addParameter(new Parameter(integerType, columnName + "_min", " @ApiParam(value = \"" + columnName
                                    + ">=此值 \") @RequestParam(value = \"" + columnName + "_min\", required = false)"));
                            method.addParameter(new Parameter(integerType, columnName + "", " @ApiParam(value = \"" + columnName
                                    + "=此值 \") @RequestParam(value = \"" + columnName + "\", required = false)"));
                        } else if ("long".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            method.addParameter(new Parameter(longType, columnName + "_max", " @ApiParam(value = \"" + columnName
                                    + "<=此值 \") @RequestParam(value = \"" + columnName + "_max\", required = false)"));
                            method.addParameter(new Parameter(longType, columnName + "_min", " @ApiParam(value = \"" + columnName
                                    + ">=此值 \") @RequestParam(value = \"" + columnName + "_min\", required = false)"));
                            method.addParameter(new Parameter(longType, columnName + "", " @ApiParam(value = \"" + columnName
                                    + "=此值 \") @RequestParam(value = \"" + columnName + "\", required = false)"));
                        } else if ("short".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            method.addParameter(new Parameter(shortType, columnName + "_max", " @ApiParam(value = \"" + columnName
                                    + "<=此值 \") @RequestParam(value = \"" + columnName + "_max\", required = false)"));
                            method.addParameter(new Parameter(shortType, columnName + "_min", " @ApiParam(value = \"" + columnName
                                    + ">=此值 \") @RequestParam(value = \"" + columnName + "_min\", required = false)"));
                            method.addParameter(new Parameter(shortType, columnName + "", " @ApiParam(value = \"" + columnName
                                    + "=此值 \") @RequestParam(value = \"" + columnName + "\", required = false)"));
                        }
                    } else {
                        if ("java.lang.Boolean".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            method.addParameter(new Parameter(booleanType, columnName, " @ApiParam(value = \"" + columnName
                                    + "=true/false\") @RequestParam(value = \"" + columnName + "\", required = false)"));
                        } else if ("java.lang.Character".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            method.addParameter(new Parameter(characterType, columnName, " @ApiParam(value = \"" + columnName
                                    + "=此值\") @RequestParam(value = \"" + columnName + "\", required = false)"));
                        } else if ("java.lang.Byte".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            method.addParameter(new Parameter(byteType, columnName + "_max", " @ApiParam(value = \"" + columnName
                                    + "<=此值 \") @RequestParam(value = \"" + columnName + "_max\", required = false)"));
                            method.addParameter(new Parameter(byteType, columnName + "_min", " @ApiParam(value = \"" + columnName
                                    + ">=此值 \") @RequestParam(value = \"" + columnName + "_min\", required = false)"));
                            method.addParameter(new Parameter(byteType, columnName + "", " @ApiParam(value = \"" + columnName
                                    + "=此值 \") @RequestParam(value = \"" + columnName + "\", required = false)"));
                        } else if ("java.lang.Double".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            method.addParameter(new Parameter(doubleType, columnName + "_max", " @ApiParam(value = \"" + columnName
                                    + "<=此值 \") @RequestParam(value = \"" + columnName + "_max\", required = false)"));
                            method.addParameter(new Parameter(doubleType, columnName + "_min", " @ApiParam(value = \"" + columnName
                                    + ">=此值 \") @RequestParam(value = \"" + columnName + "_min\", required = false)"));
                            method.addParameter(new Parameter(doubleType, columnName + "", " @ApiParam(value = \"" + columnName
                                    + "=此值 \") @RequestParam(value = \"" + columnName + "\", required = false)"));
                        } else if ("java.lang.Float".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            method.addParameter(new Parameter(floatType, columnName + "_max", " @ApiParam(value = \"" + columnName
                                    + "<=此值 \") @RequestParam(value = \"" + columnName + "_max\", required = false)"));
                            method.addParameter(new Parameter(floatType, columnName + "_min", " @ApiParam(value = \"" + columnName
                                    + ">=此值 \") @RequestParam(value = \"" + columnName + "_min\", required = false)"));
                            method.addParameter(new Parameter(floatType, columnName + "", " @ApiParam(value = \"" + columnName
                                    + "=此值 \") @RequestParam(value = \"" + columnName + "\", required = false)"));
                        } else if ("java.lang.Integer".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            method.addParameter(new Parameter(integerType, columnName + "_max", " @ApiParam(value = \"" + columnName
                                    + "<=此值 \") @RequestParam(value = \"" + columnName + "_max\", required = false)"));
                            method.addParameter(new Parameter(integerType, columnName + "_min", " @ApiParam(value = \"" + columnName
                                    + ">=此值 \") @RequestParam(value = \"" + columnName + "_min\", required = false)"));
                            method.addParameter(new Parameter(integerType, columnName + "", " @ApiParam(value = \"" + columnName
                                    + "=此值 \") @RequestParam(value = \"" + columnName + "\", required = false)"));
                        } else if ("java.lang.Long".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            method.addParameter(new Parameter(longType, columnName + "_max", " @ApiParam(value = \"" + columnName
                                    + "<=此值 \") @RequestParam(value = \"" + columnName + "_max\", required = false)"));
                            method.addParameter(new Parameter(longType, columnName + "_min", " @ApiParam(value = \"" + columnName
                                    + ">=此值 \") @RequestParam(value = \"" + columnName + "_min\", required = false)"));
                            method.addParameter(new Parameter(longType, columnName + "", " @ApiParam(value = \"" + columnName
                                    + "=此值 \") @RequestParam(value = \"" + columnName + "\", required = false)"));
                        } else if ("java.lang.Short".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            method.addParameter(new Parameter(shortType, columnName + "_max", " @ApiParam(value = \"" + columnName
                                    + "<=此值 \") @RequestParam(value = \"" + columnName + "_max\", required = false)"));
                            method.addParameter(new Parameter(shortType, columnName + "_min", " @ApiParam(value = \"" + columnName
                                    + ">=此值 \") @RequestParam(value = \"" + columnName + "_min\", required = false)"));
                            method.addParameter(new Parameter(shortType, columnName + "", " @ApiParam(value = \"" + columnName
                                    + "=此值 \") @RequestParam(value = \"" + columnName + "\", required = false)"));
                        } else if ("java.lang.BigDecimal".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            method.addParameter(new Parameter(bigDecimalType, columnName + "_max", " @ApiParam(value = \"" + columnName
                                    + "<=此值 \") @RequestParam(value = \"" + columnName + "_max\", required = false)"));
                            method.addParameter(new Parameter(bigDecimalType, columnName + "_min", " @ApiParam(value = \"" + columnName
                                    + ">=此值 \") @RequestParam(value = \"" + columnName + "_min\", required = false)"));
                            method.addParameter(new Parameter(bigDecimalType, columnName + "", " @ApiParam(value = \"" + columnName
                                    + "=此值 \") @RequestParam(value = \"" + columnName + "\", required = false)"));
                        } else if ("java.util.Date".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            method.addParameter(new Parameter(dateType, columnName + "_max", " @ApiParam(value = \"" + columnName
                                    + "<=此值 \") @RequestParam(value = \"" + columnName + "_max\", required = false)"));
                            method.addParameter(new Parameter(dateType, columnName + "_min", " @ApiParam(value = \"" + columnName
                                    + ">=此值 \") @RequestParam(value = \"" + columnName + "_min\", required = false)"));
                            method.addParameter(new Parameter(dateType, columnName + "", " @ApiParam(value = \"" + columnName
                                    + "=此值 \") @RequestParam(value = \"" + columnName + "\", required = false)"));
                        } else if ("java.lang.String".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            method.addParameter(new Parameter(stringType, columnName + "_prefix", " @ApiParam(value = \"" + columnName
                                    + " like '%此值' \") @RequestParam(value = \"" + columnName + "_prefix\", required = false)"));
                            method.addParameter(new Parameter(stringType, columnName + "_suffix", " @ApiParam(value = \"" + columnName
                                    + " like '此值%' \") @RequestParam(value = \"" + columnName + "_suffix\", required = false)"));
                            method.addParameter(new Parameter(stringType, columnName + "_like", " @ApiParam(value = \"" + columnName
                                    + " like '%此值%' \") @RequestParam(value = \"" + columnName + "_like\", required = false)"));
                            method.addParameter(new Parameter(stringType, columnName + "", " @ApiParam(value = \"" + columnName
                                    + "=此值 \") @RequestParam(value = \"" + columnName + "\", required = false)"));
                        }
                    }
                }
            }
        }
    }

    public static String getParameterWithAnnotationForColumnsWithMaxMinPrefixSuffixLike(IntrospectedTable introspectedTable) {
        String parameter = "";
        List<IntrospectedColumn> introspectedColumns;
        if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
            introspectedColumns = introspectedTable.getNonBLOBColumns();
        } else {
            introspectedColumns = introspectedTable.getAllColumns();
        }
        Iterator<IntrospectedColumn> iterator = introspectedColumns.iterator();
        List<String> columnNames = new ArrayList<>();
        while (iterator.hasNext()) {
            IntrospectedColumn introspectedColumn = iterator.next();
            if (introspectedColumn.isBLOBColumn()) {
            } else {
                FullyQualifiedJavaType fullyQualifiedJavaType = introspectedColumn
                        .getFullyQualifiedJavaType();
                String columnName = introspectedColumn.getJavaProperty();
                if (columnNames.contains(columnName)) {
                } else {
                    columnNames.add(columnName);
                    if (fullyQualifiedJavaType.isPrimitive()) {
                        if ("boolean".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+ " @ApiParam(value = \"" + columnName
                                    + "=true/false\") @RequestParam(value = \"" + columnName + "\", required = false) Boolean "+columnName+",\n";
                        } else if ("char".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+ " @ApiParam(value = \"" + columnName
                                    + "=此值\") @RequestParam(value = \"" + columnName + "\", required = false) Character "+columnName+",\n";
                        } else if ("byte".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+ addParameterForSpecialType(columnName,"Byte");
                        } else if ("double".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+ addParameterForSpecialType(columnName,"Double");
                        } else if ("float".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+ addParameterForSpecialType(columnName,"Float");
                        } else if ("int".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+ addParameterForSpecialType(columnName,"Integer");
                        } else if ("long".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+ addParameterForSpecialType(columnName,"Long");
                        } else if ("short".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+ addParameterForSpecialType(columnName,"Short");
                        }
                    } else {
                        if ("java.lang.Boolean".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+ " @ApiParam(value = \"" + columnName
                                    + "=true/false\") @RequestParam(value = \"" + columnName + "\", required = false) Boolean "+columnName+",\n";
                        } else if ("java.lang.Character".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+ " @ApiParam(value = \"" + columnName
                                    + "=此值\") @RequestParam(value = \"" + columnName + "\", required = false) Character "+columnName+",\n";
                        } else if ("java.lang.Byte".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+ addParameterForSpecialType(columnName,"Byte");
                        } else if ("java.lang.Double".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+ addParameterForSpecialType(columnName,"Double");
                        } else if ("java.lang.Float".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+ addParameterForSpecialType(columnName,"Float");
                        } else if ("java.lang.Integer".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+ addParameterForSpecialType(columnName,"Integer");
                        } else if ("java.lang.Long".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+ addParameterForSpecialType(columnName,"Long");
                        } else if ("java.lang.Short".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+ addParameterForSpecialType(columnName,"Short");
                        } else if ("java.lang.BigDecimal".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+ addParameterForSpecialType(columnName,"BigDecimal");
                        } else if ("java.util.Date".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+ addParameterForSpecialType(columnName,"Date");
                        } else if ("java.lang.String".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+ " @ApiParam(value = \"" + columnName
                                    + " like '%此值' \") @RequestParam(value = \"" + columnName + "_prefix\", required = false) String "+columnName + "_prefix,\n";
                            parameter = parameter+"                             "+ " @ApiParam(value = \"" + columnName
                                    + " like '此值%' \") @RequestParam(value = \"" + columnName + "_suffix\", required = false) String "+columnName + "_suffix,\n";
                            parameter = parameter+"                             "+ " @ApiParam(value = \"" + columnName
                                    + " like '%此值%' \") @RequestParam(value = \"" + columnName + "_like\", required = false) String "+columnName + "_like,\n";
                            parameter = parameter+"                             "+ " @ApiParam(value = \"" + columnName
                                    + " =此值 \") @RequestParam(value = \"" + columnName + "\", required = false) String "+columnName + ",\n";
                        }
                    }
                }
            }
        }
        return parameter.substring(0,parameter.length()-2);
    }

    public static String addParameterForSpecialType(String columnName, String type){
        String parameter = "";
        parameter = parameter+ " @ApiParam(value = \"" + columnName
                + "<=此值 \") @RequestParam(value = \"" + columnName + "_max\", required = false) "+type+" "+columnName + "_max"+",\n";
        parameter = parameter+"                             "+ " @ApiParam(value = \"" + columnName
                + ">=此值 \") @RequestParam(value = \"" + columnName + "_min\", required = false) "+type+" "+columnName + "_min"+",\n";
        parameter = parameter+"                             "+ " @ApiParam(value = \"" + columnName
                + "=此值 \") @RequestParam(value = \"" + columnName + "\", required = false) "+type+" "+columnName + ",\n";
        return parameter;
    }

    public static String getParameterWithoutAnnotationForColumnsWithMaxMinPrefixSuffixLike(IntrospectedTable introspectedTable) {
        String parameter = "";
        List<IntrospectedColumn> introspectedColumns;
        if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
            introspectedColumns = introspectedTable.getNonBLOBColumns();
        } else {
            introspectedColumns = introspectedTable.getAllColumns();
        }
        Iterator<IntrospectedColumn> iterator = introspectedColumns.iterator();
        List<String> columnNames = new ArrayList<>();
        while (iterator.hasNext()) {
            IntrospectedColumn introspectedColumn = iterator.next();
            if (introspectedColumn.isBLOBColumn()) {
            } else {
                FullyQualifiedJavaType fullyQualifiedJavaType = introspectedColumn
                        .getFullyQualifiedJavaType();
                String columnName = introspectedColumn.getJavaProperty();
                if (columnNames.contains(columnName)) {
                } else {
                    columnNames.add(columnName);
                    if (fullyQualifiedJavaType.isPrimitive()) {
                        if ("boolean".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+" Boolean "+columnName+",\n";
                        } else if ("char".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+" Character "+columnName+",\n";
                        } else if ("byte".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+addParameterWithoutAnnotationForSpecialType(columnName,"Byte");
                        } else if ("double".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+addParameterWithoutAnnotationForSpecialType(columnName,"Double");
                        } else if ("float".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+addParameterWithoutAnnotationForSpecialType(columnName,"Float");
                        } else if ("int".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+addParameterWithoutAnnotationForSpecialType(columnName,"Integer");
                        } else if ("long".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+addParameterWithoutAnnotationForSpecialType(columnName,"Long");
                        } else if ("short".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+addParameterWithoutAnnotationForSpecialType(columnName,"Short");
                        }
                    } else {
                        if ("java.lang.Boolean".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+" Boolean "+columnName+",\n";
                        } else if ("java.lang.Character".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+" Character "+columnName+",\n";
                        } else if ("java.lang.Byte".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+addParameterWithoutAnnotationForSpecialType(columnName,"Byte");
                        } else if ("java.lang.Double".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+addParameterWithoutAnnotationForSpecialType(columnName,"Double");
                        } else if ("java.lang.Float".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+addParameterWithoutAnnotationForSpecialType(columnName,"Float");
                        } else if ("java.lang.Integer".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+addParameterWithoutAnnotationForSpecialType(columnName,"Integer");
                        } else if ("java.lang.Long".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+addParameterWithoutAnnotationForSpecialType(columnName,"Long");
                        } else if ("java.lang.Short".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+addParameterWithoutAnnotationForSpecialType(columnName,"Short");
                        } else if ("java.lang.BigDecimal".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+addParameterWithoutAnnotationForSpecialType(columnName,"BigDecimal");
                        } else if ("java.util.Date".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+addParameterWithoutAnnotationForSpecialType(columnName,"Date");
                        } else if ("java.lang.String".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"                             "+" String "+columnName + "_prefix,\n";
                            parameter = parameter+"                             "+" String "+columnName + "_suffix,\n";
                            parameter = parameter+"                             "+" String "+columnName + "_like,\n";
                            parameter = parameter+"                             "+" String "+columnName + ",\n";
                        }
                    }
                }
            }
        }
        return parameter.substring(0,parameter.length()-2);
    }

    public static String addParameterWithoutAnnotationForSpecialType(String columnName, String type){
        String parameter = "";
        parameter = parameter+ " "+type+" "+columnName + "_max"+",\n";
        parameter = parameter+ "                              "+type+" "+columnName + "_min"+",\n";
        parameter = parameter+ "                              "+type+" "+columnName + ",\n";
        return parameter;
    }

    public static String getParameterWithoutAnnotationWithoutTypeForColumnsWithMaxMinPrefixSuffixLike(IntrospectedTable introspectedTable) {
        String parameter = "";
        List<IntrospectedColumn> introspectedColumns;
        if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
            introspectedColumns = introspectedTable.getNonBLOBColumns();
        } else {
            introspectedColumns = introspectedTable.getAllColumns();
        }
        Iterator<IntrospectedColumn> iterator = introspectedColumns.iterator();
        List<String> columnNames = new ArrayList<>();
        while (iterator.hasNext()) {
            IntrospectedColumn introspectedColumn = iterator.next();
            if (introspectedColumn.isBLOBColumn()) {
            } else {
                FullyQualifiedJavaType fullyQualifiedJavaType = introspectedColumn
                        .getFullyQualifiedJavaType();
                String columnName = introspectedColumn.getJavaProperty();
                if (columnNames.contains(columnName)) {
                } else {
                    columnNames.add(columnName);
                    if (fullyQualifiedJavaType.isPrimitive()) {
                        if ("boolean".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"               "+" "+columnName+",\n";
                        } else if ("char".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"               "+" "+columnName+",\n";
                        } else if ("byte".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"               "+addParameterWithoutAnnotationWithoutTypeForSpecialType(columnName);
                        } else if ("double".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"               "+addParameterWithoutAnnotationWithoutTypeForSpecialType(columnName);
                        } else if ("float".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"               "+addParameterWithoutAnnotationWithoutTypeForSpecialType(columnName);
                        } else if ("int".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"               "+addParameterWithoutAnnotationWithoutTypeForSpecialType(columnName);
                        } else if ("long".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"               "+addParameterWithoutAnnotationWithoutTypeForSpecialType(columnName);
                        } else if ("short".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"               "+addParameterWithoutAnnotationWithoutTypeForSpecialType(columnName);
                        }
                    } else {
                        if ("java.lang.Boolean".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"               "+" "+columnName+",\n";
                        } else if ("java.lang.Character".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"               "+" "+columnName+",\n";
                        } else if ("java.lang.Byte".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"               "+addParameterWithoutAnnotationWithoutTypeForSpecialType(columnName);
                        } else if ("java.lang.Double".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"               "+addParameterWithoutAnnotationWithoutTypeForSpecialType(columnName);
                        } else if ("java.lang.Float".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"               "+addParameterWithoutAnnotationWithoutTypeForSpecialType(columnName);
                        } else if ("java.lang.Integer".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"               "+addParameterWithoutAnnotationWithoutTypeForSpecialType(columnName);
                        } else if ("java.lang.Long".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"               "+addParameterWithoutAnnotationWithoutTypeForSpecialType(columnName);
                        } else if ("java.lang.Short".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"               "+addParameterWithoutAnnotationWithoutTypeForSpecialType(columnName);
                        } else if ("java.lang.BigDecimal".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"               "+addParameterWithoutAnnotationWithoutTypeForSpecialType(columnName);
                        } else if ("java.util.Date".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"               "+addParameterWithoutAnnotationWithoutTypeForSpecialType(columnName);
                        } else if ("java.lang.String".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                            parameter = parameter+"               "+" "+columnName + "_prefix,\n";
                            parameter = parameter+"               "+" "+columnName + "_suffix,\n";
                            parameter = parameter+"               "+" "+columnName + "_like,\n";
                            parameter = parameter+"               "+" "+columnName + ",\n";
                        }
                    }
                }
            }
        }
        return parameter.substring(0,parameter.length()-2);
    }

    public static String addParameterWithoutAnnotationWithoutTypeForSpecialType(String columnName){
        String parameter = "";
        parameter = parameter+ " "+columnName + "_max"+",\n";
        parameter = parameter+ "                "+columnName + "_min"+",\n";
        parameter = parameter+ "                "+columnName + ",\n";
        return parameter;
    }

    public static void addCriteriaForColumnsInMethod(Method method, IntrospectedTable introspectedTable) {
        List<IntrospectedColumn> introspectedColumns = introspectedTable.getAllColumns();
        Iterator<IntrospectedColumn> iterator = introspectedColumns.iterator();
        while (iterator.hasNext()) {
            IntrospectedColumn introspectedColumn = iterator.next();
            FullyQualifiedJavaType fullyQualifiedJavaType = introspectedColumn
                    .getFullyQualifiedJavaType();
            String columnName = introspectedColumn.getJavaProperty();
            if (introspectedColumn.isBLOBColumn()) {
            } else {
                if (fullyQualifiedJavaType.isPrimitive()) {
                    if ("boolean".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        method.addBodyLine("if(" + columnName + "!=null){");
                        method.addBodyLine("criteria.and" + toUpperCaseAtFirstCharacter(columnName) + "EqualTo(" + columnName + ");");
                        method.addBodyLine("}");
                    } else if ("byte".equals(fullyQualifiedJavaType.getFullyQualifiedName())
                            || "double".equals(fullyQualifiedJavaType.getFullyQualifiedName())
                            || "float".equals(fullyQualifiedJavaType.getFullyQualifiedName())
                            || "int".equals(fullyQualifiedJavaType.getFullyQualifiedName())
                            || "long".equals(fullyQualifiedJavaType.getFullyQualifiedName())
                            || "short".equals(fullyQualifiedJavaType.getFullyQualifiedName())
                    ) {
                        method.addBodyLine("if(" + columnName + "!=null){");
                        method.addBodyLine("criteria.and" + toUpperCaseAtFirstCharacter(columnName) + "EqualTo(" + columnName + ");");
                        method.addBodyLine("}");
                        method.addBodyLine("if(" + columnName + "_max!=null){");
                        method.addBodyLine("criteria.and" + toUpperCaseAtFirstCharacter(columnName) + "LessThanOrEqualTo(" + columnName + "_max);");
                        method.addBodyLine("}");
                        method.addBodyLine("if(" + columnName + "_min!=null){");
                        method.addBodyLine("criteria.and" + toUpperCaseAtFirstCharacter(columnName) + "GreaterThanOrEqualTo(" + columnName + "_min);");
                        method.addBodyLine("}");
                    } else if ("char".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                    }
                } else {
                    if ("java.lang.Boolean".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        method.addBodyLine("if(" + columnName + "!=null){");
                        method.addBodyLine("criteria.and" + toUpperCaseAtFirstCharacter(columnName) + "EqualTo(" + columnName + ");");
                        method.addBodyLine("}");
                    } else if ("java.lang.Byte".equals(fullyQualifiedJavaType.getFullyQualifiedName())
                            || "java.lang.Double".equals(fullyQualifiedJavaType.getFullyQualifiedName())
                            || "java.lang.Integer".equals(fullyQualifiedJavaType.getFullyQualifiedName())
                            || "java.lang.Long".equals(fullyQualifiedJavaType.getFullyQualifiedName())
                            || "java.lang.Short".equals(fullyQualifiedJavaType.getFullyQualifiedName())
                            || "java.lang.BigDecimal".equals(fullyQualifiedJavaType.getFullyQualifiedName())
                            || "java.util.Date".equals(fullyQualifiedJavaType.getFullyQualifiedName())
                    ) {
                        method.addBodyLine("if(" + columnName + "!=null){");
                        method.addBodyLine("criteria.and" + toUpperCaseAtFirstCharacter(columnName) + "EqualTo(" + columnName + ");");
                        method.addBodyLine("}");
                        method.addBodyLine("if(" + columnName + "_max!=null){");
                        method.addBodyLine("criteria.and" + toUpperCaseAtFirstCharacter(columnName) + "LessThanOrEqualTo(" + columnName + "_max);");
                        method.addBodyLine("}");
                        method.addBodyLine("if(" + columnName + "_min!=null){");
                        method.addBodyLine("criteria.and" + toUpperCaseAtFirstCharacter(columnName) + "GreaterThanOrEqualTo(" + columnName + "_min);");
                        method.addBodyLine("}");
                    } else if ("java.lang.String".equals(fullyQualifiedJavaType.getFullyQualifiedName())) {
                        method.addBodyLine("if(" + columnName + "!=null){");
                        method.addBodyLine("criteria.and" + toUpperCaseAtFirstCharacter(columnName) + "EqualTo(" + columnName + ");");
                        method.addBodyLine("}");
                        method.addBodyLine("if(" + columnName + "_prefix!=null){");
                        method.addBodyLine("criteria.and" + toUpperCaseAtFirstCharacter(columnName) + "Like(\"%\"+" + columnName + "_prefix);");
                        method.addBodyLine("}");
                        method.addBodyLine("if(" + columnName + "_suffix!=null){");
                        method.addBodyLine("criteria.and" + toUpperCaseAtFirstCharacter(columnName) + "Like(" + columnName + "_suffix+\"%\");");
                        method.addBodyLine("}");
                        method.addBodyLine("if(" + columnName + "_like!=null){");
                        method.addBodyLine("criteria.and" + toUpperCaseAtFirstCharacter(columnName) + "Like(\"%\"+" + columnName + "_like+\"%\");");
                        method.addBodyLine("}");
                    }
                }
            }
        }
    }

    public static String getProperCase(String s) {
        return s.substring(0, 1).toUpperCase() + s.substring(1);
    }

    public static String getTableName(IntrospectedTable introspectedTable, String modelUrl) {
        String table = introspectedTable.getBaseRecordType();
        String tableName = table.replaceAll(modelUrl + ".", "");
        return toLowerCaseAtFirstCharacter(tableName);
    }

}
